package com.gxuwz.medical.dao;

import java.awt.color.CMMException;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.List;

import com.gxuwz.medical.domain.family.Family;
import com.gxuwz.medical.domain.money.Money;
import com.gxuwz.medical.exception.DbException;

public class MoneyDao extends GenericDao<Money> {

	@Override
	protected Money handle(ResultSet rs) throws SQLException {
		try{
			Money money = new Money();
			money.setId(rs.getString("id"));
			money.setName(rs.getString("name"));
			money.setStandard(rs.getString("standard"));
			money.setLasttime(rs.getString("lasttime"));
			money.setEffectiveage(rs.getString("effectiveage"));
			money.setPay(rs.getString("pay"));
			money.setAggregate(rs.getString("aggregate"));
			money.setInvoicenumber(rs.getString("invoicenumber"));
			money.setOperator(rs.getString("operator"));
			money.setCmscode(rs.getString("cmscode"));
			/*money.setFamilyholdername(rs.getString("familyholdername"));
			money.setIdcard(rs.getString("idcard"));
			money.setRelative(rs.getString("relative"));
			money.setSex(rs.getString("sex"));
			money.setFamilycode(rs.getString("familycode"));*/
			return money;
		}catch(SQLException e){
			
			throw new SQLException("结果集转为实例失败!",e);
		}
	}
	
	/*public List<Money> findListByFamilyholdername(String familyholdername)throws DbException{
		try{
			String sql="select a.*,b.familyholdername,c.cmscode,c.name,c.relative,c.idcard,c.sex,c.familycode,a.pay "
					+ "from t_join_money a,t_family b,t_family_member c "
					+ "where b.familycode=c.familycode and c.relative=? and b.familyholdername =?";
			Object[]params={"户主",familyholdername};
			return super.queryOjects(sql, params);
			}catch(SQLException e){
				
				throw new DbException("条件查找缴费户主失败",e);
			}
	}
	
	public List<Money> findAll(String familycode)throws DbException{
		try{
			String sql="select a.aggregate,a.effectiveage,a.id,a.invoicenumber,a.lasttime,a.operator,a.pay,a.standard,b.familyholdername,c.cmscode,c.name,c.relative,c.idcard,c.sex,c.familycode "
					+ "from t_join_money a,t_family b,t_family_member c "
					+ "where b.familycode=c.familycode and c.familycode=?";
			Object[]params={familycode};
			return super.queryOjects(sql, params);
			}catch(SQLException e){
				
				throw new DbException("根据户主查询家庭成员缴费情况失败",e);
			}
	}*/
	
	/*public List<Money> findAll()throws DbException{
		try{
			String sql="select * "
					+ "from t_join_money "
					+ "where 1=1";
			Object[]params={};
			return super.queryOjects(sql, params);
			}catch(SQLException e){
				
				throw new DbException("查询所有缴费信息失败",e);
			}
	}*/
	
	public List<Money> findAll()throws DbException{
		try{
			String sql="select a.* "
					+ "from t_join_money a,t_family_member b "
					+ "where a.name=b.name and a.cmscode=b.cmscode ORDER BY a.lasttime DESC";
			Object[]params={};
			return super.queryOjects(sql, params);
			}catch(SQLException e){
				
				throw new DbException("查询所有缴费信息失败",e);
			}
	}
	
	public List<Money> findList(String invoicenumber)throws DbException{
		try{
			String sql="select * "
					+ "from t_join_money a "
					+ "where a.invoicenumber=?";
			Object[]params={invoicenumber};
			return super.queryOjects(sql, params);
			}catch(SQLException e){
				
				throw new DbException("根据户主查询家庭成员缴费情况失败",e);
			}
	}
	
	public List<Money> find(String name,String cmscode)throws DbException{
		try{
			String sql="select * "
					+ "from t_join_money "
					+ "where name=? and cmscode=?";
			Object[]params={name,cmscode};
			return super.queryOjects(sql, params);
			}catch(SQLException e){
				
				throw new DbException("查询所有缴费信息失败",e);
			}
	}
	
	//查找出发票号一样的，并打印出该批登记信息
	public List<Money> exportList()throws DbException{
		try{
			String sql="select * "
					+ "from t_join_money "
					+ "where name=? and cmscode=?";
			Object[]params={};
			return super.queryOjects(sql, params);
			}catch(SQLException e){
				
				throw new DbException("查询所有缴费信息失败",e);
			}
	}
	
}
